#!/bin/bash

rm -rf ~/.triton/cache/*
#rm -rf dump_dir/*
export LLVM_INSTALL_PREFIX=/mnt/wangjintang/Triton/llvm-install/
input_file=$1

export TRITON_DEBUG=1
export TRITON_DEVICE_PRINT=1
export TRITON_ALWAYS_COMPILE=1
export TRITON_LLVM_DEBUG_ONLY="triton-offset-analysis,triton-unstructure-converter"
##### don't need
#export LLVM_DEBUG=1
#export MLIR_ENABLE_DUMP=1
#export LLVM_IR_ENABLE_DUMP=1
export TRITON_REPRODUCER_PATH=./dump_dir
#export TRITON_ENABLE_LLVM_DEBUG=1
#export USE_IR_LOC=1
export TRITON_KERNEL_DUMP=1
export TRITON_DUMP_DIR=./dump_dir
#export TRITON_KERNEL_OVERRIDE=1
#export TRITON_OVERRIDE_DIR=./override_dir
#export ASCEND_LAUNCH_BLOCKING=1
#export TRITON_ENABLE_SANITIZER=1

export PATH=/mnt/wangjintang/test/tmp/8.2.RC1.alpha002/compiler/bishengir/bin:$PATH
export LD_LIBRARY_PATH=/mnt/wangjintang/test/tmp/8.2.RC1.alpha002/compiler/bishengir/lib:$LD_LIBRARY_PATH

LOG_FILE="run_all_test.log"

> $LOG_FILE

run_and_log() {
    local cmd="$1"
    echo "[$(date +'%Y-%m-%d %H:%M:%S')] Executing: $cmd" 
    echo "[$(date +'%Y-%m-%d %H:%M:%S')] Executing: $cmd" >> $LOG_FILE 2>&1
    $cmd >> $LOG_FILE 2>&1
    echo "[$(date +'%Y-%m-%d %H:%M:%S')] Command finish: $cmd" >> $LOG_FILE 2>&1
    echo -e "\n" >> $LOG_FILE 2>&1
}


run_and_log "python3  causal_conv1d_fwd_kernel/*.py"
run_and_log "python3  causal_conv1d_states_fwd_kernel/*.py"
run_and_log "python3  causal_conv1d_update_kernel/*.py"
run_and_log "python3  chunk_bwd_kernel_dqkwg/*.py"
run_and_log "python3  chunk_bwd_kernel_dv_local/*.py"
run_and_log "python3  chunk_fwd_kernel_o/*.py"
run_and_log "python3  chunk_gated_delta_rule_bwd_kernel_dhu_blockdim64/*.py"
run_and_log "python3  chunk_gated_delta_rule_fwd_kernel_h_blockdim64/*.py"
run_and_log "python3  chunk_local_cumsum_vector_kernel/*.py"
run_and_log "python3  chunk_scaled_dot_kkt_fwd_kernel/*.py"
run_and_log "python3  chunk_scaled_dot_kkt_fwd_kernel_intra_sub_inter/*.py"
run_and_log "python3  fused_recurrent_gated_delta_rule_fwd_kernel/*.py"
run_and_log "python3  merge_16x16_to_32x32_inverse_kernel/*.py"
run_and_log "python3  merge_16x16_to_64x64_inverse_kernel/*.py"
run_and_log "python3  prepare_wy_repr_bwd_kernel/*.py"
run_and_log "python3  recompute_w_u_fwd_kernel/*.py"

python3 precision_test.py >> $LOG_FILE 2>&1

### precision error
#run_and_log "python3  solve_tril_16x16_kernel/*.py"
### all pass
#run_and_log "python3  chunk_local_cumsum_scalar_kernel/*.py"
#run_and_log "python3  chunk_scaled_dot_kkt_fwd_kernel_intra_sub_intra/*.py"
#run_and_log "python3  l2norm_fwd_kernel/*.py"
#run_and_log "python3  layer_norm_gated_fwd_kernel/*.py"
echo "All commands executed! Log saved to: $LOG_FILE"

